package gui;
import java.awt.Point;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.Timer;

import domain.PlayerClass;
import domain.Perk;
import files.FileManager;



public class Player {

	private Point middle;
	private PlayerClass pclass;
	private ImageIcon pimg;
	private int speed;
	private int current_health;
	private List<Perk> perks;
	private int client_id;
	
	public Player(int playerid, int x, int y, int speed){
		this.client_id = playerid;
		this.middle = new Point(x,y);
		this.speed = speed;
		this.perks = new ArrayList<Perk>();
		this.pimg = FileManager.getImage("stone");
	}

	public void addPerk(Perk p){
		perks.add(p);
	}

	public double getTeta(int x, int y){
		if(x - middle.x == 0 && y - middle.y > 0)
			return 0;
		
		if(x - middle.x == 0 && y - middle.y < 0)
			return Math.PI;
		
		if(x-middle.x > 0)
			return -Math.PI/2 + Math.atan((double)(y-middle.y)/(double)(x-middle.x));
		
		if(x-middle.x < 0)
			return Math.PI/2 + Math.atan((double)(y-middle.y)/(double)(x-middle.x));
		
		return 0;
		
	}
	
	public void moveX(int x){
		middle.x = x;
	}
	
	public void moveY(int y){
		middle.y = y;
	}
	
	public int getX(){
		return middle.x;
	}
	
	public int getY(){
		return middle.y;
	}

	public int getSpeed() {
		int aspeed = speed;
		for(Perk p : perks)
			aspeed += p.getSP();
		return aspeed;
	}
	
	public PlayerClass getPClass(){
		return pclass;
	}

	public ImageIcon getIcon() {
		return pimg;
	}
	
}
